var t = require("../../@babel/runtime/helpers/toConsumableArray"), a = getApp();

Page({
    data: {
        earnings: [ {
            price: "",
            name: "累计获得奖励"
        }, {
            price: "",
            name: "已结算金额"
        }, {
            price: "",
            name: "未结算金额"
        } ],
        earningsPrice: [ "total_reward", "already_settled", "not_settled" ],
        orderSelection: [ {
            title: "全部",
            name: "all"
        }, {
            title: "已结算",
            name: 1
        }, {
            title: "未结算",
            name: 0
        } ],
        activeName: "",
        listOfTime: [],
        orderList: [],
        orderPage: 1,
        page: 1,
        orderLastPage: !1,
        labelStatus: "unselected"
    },
    onLoad: function(t) {},
    onReady: function() {},
    onShow: function() {
        this.getData();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    getData: function(t) {
        var e = this, n = {
            page: this.data.page
        };
        "all" != t && null != t && (n.settlement_status = t);
        var s = a.getNetAddresss("plugin.agent-earnings.frontend.reward-log.get-reward-list");
        a._postNetWork({
            url: s,
            data: n,
            success: function(t) {
                var a = t.data;
                if (1 == a.result) {
                    var n = e.data.earnings;
                    e.data.earnings.forEach(function(t, s) {
                        n[s].price = a.data.reward_summarize[e.data.earningsPrice[s]];
                    }), e.setData({
                        agentLevel: a.data.agent_info.has_one_level.level_name,
                        username: a.data.agent_info.has_one_member.username,
                        avatar_image: a.data.agent_info.has_one_member.avatar_image,
                        listOfTime: a.data.list,
                        earnings: n
                    });
                } else wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getOrderList: function(e, n) {
        var s = this;
        if ("number" == typeof e && (e = this.data.listOfTime[e].sub_month_str), "more" != n && this.setData({
            orderPage: 1
        }), e) {
            var r = {
                month_str: e,
                page: this.data.orderPage
            };
            "unselected" != this.data.labelStatus && "all" != this.data.labelStatus.detail.name && (r.settlement_status = this.data.labelStatus.detail.name);
            var i = a.getNetAddresss("plugin.agent-earnings.frontend.reward-log.get-reward-list-to-month");
            a._postNetWork({
                url: i,
                data: r,
                success: function(a) {
                    var e = a.data;
                    1 == e.result ? (s.setData({
                        orderLastPage: !1
                    }), e.data.list.current_page >= e.data.list.last_page && s.setData({
                        orderLastPage: !0
                    }), "more" == n ? (s.setData({
                        orderList: [].concat(t(s.data.orderList), t(e.data.list.data))
                    }), console.log("9999", s.data.orderList)) : s.setData({
                        orderList: e.data.list.data
                    }), s.setData({
                        pagingChoose: e.data.list
                    })) : wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1e3
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    readMore: function(t) {
        var a = this.data.orderPage;
        a++, this.setData({
            orderPage: a
        }), this.getOrderList(t.currentTarget.dataset.sub_month_str, "more");
    },
    clickChange: function(t) {
        this.getData(t.detail.name), this.setData({
            activeName: "",
            labelStatus: t
        });
    },
    foldChange: function(t) {
        this.setData({
            activeName: t.detail
        }), "" == t.detail && (t.detail = 0), this.getOrderList(t.detail);
    },
    onShareAppMessage: function() {}
});